AGC033 A - Darker and Darker
提出
code: python
from collections import deque
h, w = map(int,input().split())
black = []
for i in range(h):
for j in range(w):
def dfs(q):
nowi, nowj = q.popleft()
# 多点スタート
for i in black:
dfs(q)
解答
code: python
from collections import deque
h, w = map(int, input().split())
dist = [-1 * w for _ in range(h)] black_cells = deque()
for i in range(h):
for j in range(w):
black_cells.append((i, j))
while black_cells:
nowi, nowj = black_cells.popleft()
for i, j in ((1, 0), (0, 1), (-1, 0), (0, -1)):
nexti, nextj = nowi + i, nowj + j
if nexti < 0 or h - 1 < nexti or nextj < 0 or w - 1 < nextj or distnextinextj != -1: continue
else:
black_cells.append((nexti, nextj))
# print(dist)
# ..#..#
# ......
# ......
# .#....
# ....#.
# 2, 1, 0, 1, 1, 0], 1, 2, 1, 1, 2, 1, 0, 1, 1, 0, 1, 2, 1, 1, 2, 1, 2, 3, 1, 0, 1, 2, 1, 2, [2, 1, 2, 1, 0, 1 ans = -1
for i in range(h):
for j in range(w):
if (res > ans):
ans = res
print(ans)
テーマ
メモ
提出
code: python
from collections import deque
h, w = map(int,input().split())
print(a)
for i in range(h):
for j in range(w):
if i - 1 >= 0:
elif i + 1 <= h:
elif j - 1 >= 0:
elif j + 1 <= w:
print(a)